package com.example.jdai.jdai.ui;

import android.app.Activity;
import android.net.http.SslError;
import android.os.Bundle;
import android.util.Log;
import android.webkit.SslErrorHandler;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.example.jdai.jdai.MyApplication;
import com.example.jdai.jdai.R;
import com.example.jdai.jdai.config.Config;
import com.example.jdai.jdai.util.DataAll;

import butterknife.BindView;
import butterknife.ButterKnife;

public class WebActivity extends Activity {
    String url="";
    String title="";
    @BindView(R.id.tb)
    TopBar tb;
    @BindView(R.id.wb_zm)
    WebView wbZm;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        url = getIntent().getStringExtra("url");
        Log.v("url",url);
        title= getIntent().getStringExtra("title");
        setContentView(R.layout.activity_web);
        ButterKnife.bind(this);
        tb.setTopBarLisener(new TopBar.TopBarLisener() {
            @Override
            public void back() {
                finish();
            }

            @Override
            public void more() {

            }
        });
        tb.setTitle(title);
        initWeb();

    }

    void initWeb() {
        wbZm.getSettings().setJavaScriptEnabled(true);
        wbZm.getSettings().setSupportZoom(true);
        wbZm.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
        wbZm.getSettings().setLoadWithOverviewMode(true);
        wbZm.setWebViewClient(new WebViewClient() {
            public boolean shouldOverrideUrlLoading(WebView view, String url) { //  重写此方法表明点击网页里面的链接还是在当前的webview里跳转，不跳到浏览器那边
                view.loadUrl(url);
                return true;
            }

            @Override
            public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
                //super.onReceivedSslError(view, handler, error);
                handler.proceed();  // 接受所有网站的证书
            }
        });
        wbZm.loadUrl(url);
    }

}
